<!DOCTYPE html><html lang="en" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>SpringBoot | Cying</title><meta name="keywords" content="JavaEE"><meta name="author" content="Cying-承影"><meta name="copyright" content="Cying-承影"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="SpringBoot   一、SpringBoot 入门1.1 - 简介 Spring 简化 Spring 应用开发，约定大约配置，去繁从简 整个 Spring 技术栈的一个大集合 J2EE 开发的一站式解决方案  1.1.1.背景 J2EE 笨重的开发、繁多的配置、低下的开发效率，复杂的部署流程、第三方技术集成难度大  1.1.2.解决  Spring 全家桶时代 Sping Boot &#x3D;&gt; J">
<meta property="og:type" content="article">
<meta property="og:title" content="SpringBoot">
<meta property="og:url" content="http://cyingk.github.io/2020/04/05/SpringBoot/index.html">
<meta property="og:site_name" content="Cying">
<meta property="og:description" content="SpringBoot   一、SpringBoot 入门1.1 - 简介 Spring 简化 Spring 应用开发，约定大约配置，去繁从简 整个 Spring 技术栈的一个大集合 J2EE 开发的一站式解决方案  1.1.1.背景 J2EE 笨重的开发、繁多的配置、低下的开发效率，复杂的部署流程、第三方技术集成难度大  1.1.2.解决  Spring 全家桶时代 Sping Boot &#x3D;&gt; J">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4157804759,1050439081&fm=26&gp=0.jpg">
<meta property="article:published_time" content="2020-04-05T08:33:36.000Z">
<meta property="article:modified_time" content="2020-07-03T16:21:31.000Z">
<meta property="article:author" content="Cying-承影">
<meta property="article:tag" content="JavaEE">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4157804759,1050439081&fm=26&gp=0.jpg"><link rel="shortcut icon" href="/img/favicon.ico"><link rel="canonical" href="http://cyingk.github.io/2020/04/05/SpringBoot/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//www.clarity.ms"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><script>(function(c,l,a,r,i,t,y){
    c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
    t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
    y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "4zndahq92q");</script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: 'days',
  date_suffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"Traditional Chinese Activated Manually","cht_to_chs":"Simplified Chinese Activated Manually","day_to_night":"Dark Mode Activated Manually","night_to_day":"Light Mode Activated Manually","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-left"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isanchor: false
};

const saveToLocal = {
  // ttl 單位是 天
  set: function setWithExpiry(key, value, ttl) {
    if (ttl === 0) return
    const now = new Date()
    const expiryDay = ttl * 86400000
    const item = {
      value: value,
      expiry: now.getTime() + expiryDay,
    }
    localStorage.setItem(key, JSON.stringify(item))
  },

  get: function getWithExpiry(key) {
    const itemStr = localStorage.getItem(key)

    if (!itemStr) {
      return undefined
    }
    const item = JSON.parse(itemStr)
    const now = new Date()

    if (now.getTime() > item.expiry) {
      localStorage.removeItem(key)
      return undefined
    }
    return item.value
  }
}

// https://stackoverflow.com/questions/16839698/jquery-getscript-alternative-in-native-javascript
const getScript = url => new Promise((resolve, reject) => {
  const script = document.createElement('script')
  script.src = url
  script.async = true
  script.onerror = reject
  script.onload = script.onreadystatechange = function() {
    const loadState = this.readyState
    if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
    script.onload = script.onreadystatechange = null
    resolve()
  }
  document.head.appendChild(script)
})</script><script id="config_change">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2020-07-04 00:21:31'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(function () {  window.activateDarkMode = function () {
    document.documentElement.setAttribute('data-theme', 'dark')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
    }
  }
  window.activateLightMode = function () {
    document.documentElement.setAttribute('data-theme', 'light')
   if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
    }
  }
  const autoChangeMode = '1'
  const t = saveToLocal.get('theme')
  if (autoChangeMode === '1') {
    const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
    const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
    const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
    const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
    if (t === undefined) {
      if (isLightMode) activateLightMode()
      else if (isDarkMode) activateDarkMode()
      else if (isNotSpecified || hasNoSupport) {
        const now = new Date()
        const hour = now.getHours()
        const isNight = hour <= 6 || hour >= 18
        isNight ? activateDarkMode() : activateLightMode()
      }
      window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
        if (saveToLocal.get('theme') === undefined) {
          e.matches ? activateDarkMode() : activateLightMode()
        }
      })
    } else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else if (autoChangeMode === '2') {
    const now = new Date()
    const hour = now.getHours()
    const isNight = hour <= 6 || hour >= 18
    if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
    else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else {
    if (t === 'dark') activateDarkMode()
    else if (t === 'light') activateLightMode()
  }const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
   if (asideStatus === 'hide') {
     document.documentElement.classList.add('hide-aside')
   } else {
     document.documentElement.classList.remove('hide-aside')
   }
}const fontSizeVal = saveToLocal.get('global-font-size')
if (fontSizeVal !== undefined) {
  document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
}})()</script><meta name="generator" content="Hexo 5.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">Loading...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="/img/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">23</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">Tags</div><div class="length-num">12</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">Categories</div><div class="length-num">3</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> Categories</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://5b0988e595225.cdn.sohucs.com/images/20190831/84729f5c5bb346208416445feb485df6.jpeg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Cying</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> Categories</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">SpringBoot</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2020-04-05T08:33:36.000Z" title="Created 2020-04-05 16:33:36">2020-04-05</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2020-07-03T16:21:31.000Z" title="Updated 2020-07-04 00:21:31">2020-07-04</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Note/">Note</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">Word count:</span><span class="word-count">4.6k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">Reading time:</span><span>20min</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><html><head></head><body><h1><center>SpringBoot</center></h1>


<h1 id="一、SpringBoot-入门"><a href="#一、SpringBoot-入门" class="headerlink" title="一、SpringBoot 入门"></a>一、SpringBoot 入门</h1><h2 id="1-1-简介"><a href="#1-1-简介" class="headerlink" title="1.1 - 简介"></a>1.1 - 简介</h2><blockquote>
<p><code>Spring</code> 简化 <code>Spring</code> 应用开发，约定大约配置，去繁从简</p>
<p>整个 <code>Spring</code> 技术栈的一个大集合</p>
<p><code>J2EE</code> 开发的一站式解决方案</p>
</blockquote>
<h3 id="1-1-1-背景"><a href="#1-1-1-背景" class="headerlink" title="1.1.1.背景"></a>1.1.1.背景</h3><blockquote>
<p><code>J2EE</code> 笨重的开发、繁多的配置、低下的开发效率，复杂的部署流程、第三方技术集成难度大</p>
</blockquote>
<h3 id="1-1-2-解决"><a href="#1-1-2-解决" class="headerlink" title="1.1.2.解决"></a>1.1.2.解决</h3><blockquote>
<ul>
<li><code>Spring</code> 全家桶时代</li>
<li><code>Sping Boot</code> => <code>J2EE</code> 一站式解决方案</li>
<li><code>Spring Cloud</code> => 分布式整体解决方案</li>
</ul>
</blockquote>
<h3 id="1-1-3-优点"><a href="#1-1-3-优点" class="headerlink" title="1.1.3.优点"></a>1.1.3.优点</h3><blockquote>
<ul>
<li>快速创建独立运行的 <code>Spring</code> 项目以及与主流框架集成</li>
<li>使用嵌入式的 <code>Servlet</code> 容器，应用无需达成 <code>War</code> 包</li>
<li><code>starters</code> 自动依赖与版本控制</li>
<li>大量的自动配置，简化开发，也可修改默认值</li>
<li>无需配置 <code>xml</code> ，无代码生成</li>
<li>准生产环境的运行时应用监控</li>
<li>与云计算的天然集成</li>
</ul>
</blockquote>
<h3 id="1-1-4-微服务"><a href="#1-1-4-微服务" class="headerlink" title="1.1.4.微服务"></a>1.1.4.微服务</h3><blockquote>
<ul>
<li>是一种架构风格</li>
<li>是一组小型服务，可以通过 <code>HTTP</code> 的方式进行沟通</li>
</ul>
</blockquote>
<h2 id="1-2-pom-xml"><a href="#1-2-pom-xml" class="headerlink" title="1.2 - pom.xml"></a>1.2 - pom.xml</h2><h3 id="1-2-1-依赖"><a href="#1-2-1-依赖" class="headerlink" title="1.2.1.依赖"></a>1.2.1.依赖</h3><h4 id="lt-parent-gt-…-lt-parent-gt"><a href="#lt-parent-gt-…-lt-parent-gt" class="headerlink" title="- <parent>…< /parent>"></a>- <parent>…< /parent></parent></h4><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># 导入 parent 依赖</span><br><span class="line"># 必要</span><br><span class="line"><span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">artifactId</span>></span>spring-boot-starter-parent<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">version</span>></span>2.3.0.M1<span class="tag">< /<span class="attr">version</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<h4 id="lt-build-gt-…-lt-bulid-gt"><a href="#lt-build-gt-…-lt-bulid-gt" class="headerlink" title="- <build>…< /bulid>"></a>- <build>…< /bulid></build></h4><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"># 导入 Maven 插件</span><br><span class="line"><span class="tag"><<span class="name">plugins</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">plugin</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">artifactId</span>></span>spring-boot-maven-plugin<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line">  <span class="tag">< /<span class="attr">plugin</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">plugins</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<h4 id="lt-dependencies-gt-…-lt-dependencies-gt"><a href="#lt-dependencies-gt-…-lt-dependencies-gt" class="headerlink" title="- <dependencies>…< /dependencies>"></a>- <dependencies>…< /dependencies></dependencies></h4><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># web 依赖</span><br><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">artifactId</span>></span>spring-boot-starter-web<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># jdbc 数据库连接依赖</span><br><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">artifactId</span>></span>spring-boot-starter-jdbc<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"># test 单元测试依赖</span><br><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">artifactId</span>></span>spring-boot-starter-test<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">scope</span>></span>test<span class="tag">< /<span class="attr">scope</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">exclusions</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">exclusion</span>></span></span><br><span class="line">      <span class="tag"><<span class="name">groupId</span>></span>org.junit.vintage<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">      <span class="tag"><<span class="name">artifactId</span>></span>junit-vintage-engine<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line">    <span class="tag">< /<span class="attr">exclusion</span>></span></span><br><span class="line">  <span class="tag">< /<span class="attr">exclusions</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"># @ConfigurationProperties 注解依赖</span><br><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">artifactId</span>></span>spring-boot-configuration-processor<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">optional</span>></span>true<span class="tag">< /<span class="attr">optional</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<h3 id="1-2-2-分析"><a href="#1-2-2-分析" class="headerlink" title="1.2.2.分析"></a>1.2.2.分析</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">parent</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">artifactId</span>></span>spring-boot-starter-parent<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">version</span>></span>2.3.0.M1<span class="tag">< /<span class="attr">version</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">parent</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<p><strong>而 <code>spring-boot-starter-parent</code> 的父项目是 <code>spring-boot-dependencies</code></strong></p>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">parent</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">artifactId</span>></span>spring-boot-dependencies<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">version</span>></span>2.3.0.M1<span class="tag">< /<span class="attr">version</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">parent</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<p><strong>在 <code>spring-boot-dependencies</code> 里有 <code>properties</code> 用来定义每一个依赖的版本</strong></p>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">properties</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">activemq.version</span>></span>5.15.11<span class="tag">< /<span class="attr">activemq.version</span>></span></span><br><span class="line">  ...</span><br><span class="line">  <span class="tag"><<span class="name">xmlunit2.version</span>></span>2.6.3<span class="tag">< /<span class="attr">xmlunit2.version</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">properties</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<h2 id="1-3-注解"><a href="#1-3-注解" class="headerlink" title="1.3. - 注解"></a>1.3. - 注解</h2><h3 id="SpringBootApplication"><a href="#SpringBootApplication" class="headerlink" title="- @SpringBootApplication"></a>- @SpringBootApplication</h3><blockquote>
<p>来表示一个主程序类，说明这是一个 SpringBoot 应用</p>
<p>其内部还有更多注解</p>
<ul>
<li><code>@SpringBootConfiguration</code>：表示这是一个配置类<ul>
<li><code>@Configuration</code> 配置类类似于配置文件，也是容器中的一个组件</li>
</ul>
</li>
<li><code>@EnableAutoConfiguration</code>：开启自动配置功能<ul>
<li><code>@AutoConfigurationPackage</code>：自动配置包，将主配置类所在的包，及其下所有子包的所有组件都扫描进去<ul>
<li><code>@Import({Registrar.class})</code>：底层注解，导入对应组件</li>
</ul>
</li>
<li><code>@Import({AutoConfigurationImportSelector.class})</code>：给容器中导入组件</li>
</ul>
</li>
</ul>
</blockquote>
<h3 id="Controller"><a href="#Controller" class="headerlink" title="- @Controller"></a>- @Controller</h3><blockquote>
<p>标在类上，用于表示一个组件</p>
</blockquote>
<h3 id="RequestMapping-“url”"><a href="#RequestMapping-“url”" class="headerlink" title="- @RequestMapping(“url”)"></a>- @RequestMapping(“url”)</h3><blockquote>
<p>用来接收 URL 请求</p>
</blockquote>
<h3 id="ResponseBody"><a href="#ResponseBody" class="headerlink" title="- @ResponseBody"></a>- @ResponseBody</h3><blockquote>
<p>用来向客户端返回信息</p>
</blockquote>
<h3 id="RestController"><a href="#RestController" class="headerlink" title="- @RestController"></a>- @RestController</h3><blockquote>
<p>集合了 <code>@ResponseBody</code> 和 <code>Controller</code></p>
</blockquote>
<h3 id="ConfigurationProperties-prefix-“对象”"><a href="#ConfigurationProperties-prefix-“对象”" class="headerlink" title="- @ConfigurationProperties(prefix = “对象”)"></a>- @ConfigurationProperties(prefix = “对象”)</h3><blockquote>
<p>标在类上，将从配置文件中获取对象的值，并赋值给该类中的属性</p>
</blockquote>
<h3 id="Value-“-”"><a href="#Value-“-”" class="headerlink" title="- @Value(“${?}”)"></a>- @Value(“${?}”)</h3><blockquote>
<p>标在属性上，直接从配置文件找到对应的配置，将值赋给该属性，取配置的时候不支持松散绑定，并且不支持复杂类型的获取</p>
</blockquote>
<h3 id="PropertySource-“classpath-”"><a href="#PropertySource-“classpath-”" class="headerlink" title="- @PropertySource(“classpath:?”)"></a>- @PropertySource(“classpath:?”)</h3><blockquote>
<p>标在类上面用于加载指定的配置文件</p>
</blockquote>
<h3 id="ImportResource-locations-“classpath-xml”"><a href="#ImportResource-locations-“classpath-xml”" class="headerlink" title="- @ImportResource(locations = {“classpath:?.xml”})"></a>- @ImportResource(locations = {“classpath:?.xml”})</h3><blockquote>
<p>标在主配置类上，用于导入自定义的 <code>Spring</code> 配置文件</p>
</blockquote>
<h3 id="Configuration"><a href="#Configuration" class="headerlink" title="- @Configuration"></a>- @Configuration</h3><blockquote>
<p>标在类上，用于表示这是一个配置类</p>
</blockquote>
<h3 id="Bean"><a href="#Bean" class="headerlink" title="- @Bean"></a>- @Bean</h3><blockquote>
<p>标在方法上，表示这是一个 <code>Bean</code>，<code>SpringBoot</code> 会将这个 <code>Bean</code> 加到配置里，<code>Bean</code> 的名字就是这个方法名</p>
</blockquote>
<h1 id="二、SpringBoot-配置"><a href="#二、SpringBoot-配置" class="headerlink" title="二、SpringBoot 配置"></a>二、SpringBoot 配置</h1><h2 id="2-1-YAML"><a href="#2-1-YAML" class="headerlink" title="2.1 - YAML"></a>2.1 - YAML</h2><blockquote>
<ul>
<li><code>A Markup Language</code> - 是一个标记语言</li>
<li><code>Isn't Markup Language</code> - 不是一个标记语言</li>
</ul>
</blockquote>
<h3 id="2-1-1-语法"><a href="#2-1-1-语法" class="headerlink" title="2.1.1.语法"></a>2.1.1.语法</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">yaml</div></div><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">key:</span> <span class="string">value</span> <span class="comment"># ':' 后面必须有一个空格</span></span><br><span class="line">	<span class="attr">key:</span> <span class="string">value</span></span><br><span class="line">	<span class="attr">key:</span> <span class="string">value</span></span><br><span class="line"><span class="attr">key:</span> <span class="string">value</span> </span><br><span class="line"></span><br><span class="line"><span class="comment"># 以左对齐为一个层级</span></span><br></pre></td></tr></tbody></table></figure></div>

<h3 id="2-1-2-字面量的表示"><a href="#2-1-2-字面量的表示" class="headerlink" title="2.1.2.字面量的表示"></a>2.1.2.字面量的表示</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">yaml</div></div><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 直接写</span></span><br><span class="line"><span class="attr">key:</span> <span class="string">value</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># "": 不会转义字符串里面的特殊字符。特殊字符会作为本身想表达的意思 "a\nb" -> "a换行b"</span></span><br><span class="line"><span class="comment"># '': 会转义特殊字符 'a\nb' -> 'a\nb'</span></span><br></pre></td></tr></tbody></table></figure></div>

<h3 id="2-1-3-对象的表示"><a href="#2-1-3-对象的表示" class="headerlink" title="2.1.3.对象的表示"></a>2.1.3.对象的表示</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">Code</div></div><figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">对象名:</span><br><span class="line">	属性1: 值1</span><br><span class="line">	属性2: 值2</span><br><span class="line">	...</span><br><span class="line">	属性n: 值n</span><br><span class="line">	</span><br><span class="line">------------------</span><br><span class="line">对象名: {属性1: 值1, 属性2: 值2, ..., 属性n: 值n}</span><br></pre></td></tr></tbody></table></figure></div>

<h3 id="2-1-4-数组的表示"><a href="#2-1-4-数组的表示" class="headerlink" title="2.1.4.数组的表示"></a>2.1.4.数组的表示</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">yaml</div></div><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">数组名:</span></span><br><span class="line"><span class="bullet">-</span> <span class="string">值1</span></span><br><span class="line"><span class="bullet">-</span> <span class="string">值2</span></span><br><span class="line"><span class="string">...</span></span><br><span class="line"><span class="bullet">-</span> <span class="string">值n</span></span><br><span class="line"></span><br><span class="line"><span class="string">----------------------------</span></span><br><span class="line"><span class="string">数组名:</span> <span class="string">[值1,</span> <span class="string">值2,</span> <span class="string">...,</span> <span class="string">值n]</span></span><br></pre></td></tr></tbody></table></figure></div>

<h2 id="2-2-Properties"><a href="#2-2-Properties" class="headerlink" title="2.2 - Properties"></a>2.2 - Properties</h2><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">properties</div></div><figure class="highlight properties"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">对象.属性1</span>=<span class="string">值1</span></span><br><span class="line"><span class="meta">对象.Map对象.key1</span>=<span class="string">value1</span></span><br><span class="line"><span class="meta">对象.Map对象.key2</span>=<span class="string">value2</span></span><br></pre></td></tr></tbody></table></figure></div>

<h2 id="2-3-Profile"><a href="#2-3-Profile" class="headerlink" title="2.3 - Profile"></a>2.3 - Profile</h2><blockquote>
<p>在开发中，对于不同的开发环境，总会有不同的配置，我们可以对不同环境进行配置</p>
</blockquote>
<h3 id="2-3-1-Properties-配置方式"><a href="#2-3-1-Properties-配置方式" class="headerlink" title="2.3.1.Properties 配置方式"></a>2.3.1.Properties 配置方式</h3><blockquote>
<p>将三个环境分别写在不同的三个配置文件中</p>
<ul>
<li><p><code>application.properties</code></p>
</li>
<li><p><code>application-dev.properties</code></p>
</li>
<li><p><code>application-prod.properties</code></p>
<p>其中以 <code>application.properties</code> 为默认，如果要更改环境，也要在 <code>application.properties</code> 里面配置 <code>spring.profiles.active='?'</code> 来激活，其中，<code>?</code> 代表 <code>dev</code> 或者 <code>prod</code></p>
</li>
</ul>
</blockquote>
<h3 id="2-3-2-Yaml-配置方式"><a href="#2-3-2-Yaml-配置方式" class="headerlink" title="2.3.2.Yaml 配置方式"></a>2.3.2.Yaml 配置方式</h3><blockquote>
<p>在 <code>.yml</code> 文件中，通常以 ‘—‘ 为分界线，将上下分为两个不同的文档块，我们可以利用这个来将不同环境的配置写在同一文件下的不同文档块，默认使用没有配置 <code>spring: profiles: ?</code> 的文档块</p>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">yaml</div></div><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"><span class="attr">profiles:</span></span><br><span class="line"> <span class="attr">active:</span> <span class="string">?</span></span><br><span class="line"><span class="meta">---</span></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line"><span class="attr">profiles:</span> <span class="string">dev</span></span><br><span class="line"><span class="meta">---</span></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line"><span class="attr">profiles:</span> <span class="string">prod</span></span><br></pre></td></tr></tbody></table></figure></div>

<p>其中，<code>?</code> 代表 <code>dev</code> 或者 <code>prod</code></p>
</blockquote>
<h3 id="2-3-3-其他方式"><a href="#2-3-3-其他方式" class="headerlink" title="2.3.3.其他方式"></a>2.3.3.其他方式</h3><blockquote>
<p>首先，配置文件还是要写好，至于是用 <code>properties</code> 方式还是 <code>yaml</code> 方式写，取决于个人爱好。在其他地方只需要去通过某种方法来启动相应环境即可</p>
</blockquote>
<p><strong>命令行方式</strong></p>
<blockquote>
<p>当项目打包之后，在命令行运行该 <code>jar</code> 包时使用</p>
<p><code>java -jar ?.jar --spring.profiles.active=?</code></p>
</blockquote>
<p><strong>虚拟机方式</strong></p>
<blockquote>
<p>当项目需要在虚拟机中运行时</p>
<p><code>-Dspring.properties.active=?</code></p>
</blockquote>
<h2 id="2-4-配置文件的加载"><a href="#2-4-配置文件的加载" class="headerlink" title="2.4.配置文件的加载"></a>2.4.配置文件的加载</h2><h3 id="2-4-1-SpringBoot-指定的位置"><a href="#2-4-1-SpringBoot-指定的位置" class="headerlink" title="2.4.1.SpringBoot 指定的位置"></a>2.4.1.SpringBoot 指定的位置</h3><blockquote>
<ul>
<li>根目录/config/?</li>
<li>根目录/?</li>
<li>resource/config/?</li>
<li>resource/?</li>
<li>加载顺序，优先级均从上到下并形成互补配置</li>
</ul>
</blockquote>
<h3 id="2-4-2-自定义的位置"><a href="#2-4-2-自定义的位置" class="headerlink" title="2.4.2.自定义的位置"></a>2.4.2.自定义的位置</h3><blockquote>
<p>这个需要打 <code>jar</code> 包后在命令行运行</p>
<p><code>--spring.config.location=yourpath</code></p>
</blockquote>
<h3 id="2-4-3-其他外部配置位置"><a href="#2-4-3-其他外部配置位置" class="headerlink" title="2.4.3.其他外部配置位置"></a>2.4.3.其他外部配置位置</h3><blockquote>
<p>优先级从高到低，高的覆盖低的，并形成互补配置</p>
<ul>
<li>命令行参数</li>
<li>来自java:comp/env的JNDI属性</li>
<li>Java系统属性( System.getProperties() )</li>
<li>操作系统环境变量</li>
<li>RandomValuePropertySource配置的random.*属性值</li>
<li>jar包外部的application-{profile}.properties或application.yml(带spring.profile)配置文件</li>
<li>jar包内部的application-{profile}.properties或application.ym(带spring.profile)配置文件</li>
<li>jar包外部的application.properties或application.yml(不带spring.profile)配置文件</li>
<li>jar包内部的application.properties或application.ym(不带spring.profile)配置文件</li>
<li>@Configuration注解类上的@PropertySource</li>
<li>通过SpringApplication.setDefaultProperties指定的默认属性</li>
</ul>
</blockquote>
<h2 id="2-5-自动配置原理"><a href="#2-5-自动配置原理" class="headerlink" title="2.5.自动配置原理"></a>2.5.自动配置原理</h2><h3 id="2-5-1-启动"><a href="#2-5-1-启动" class="headerlink" title="2.5.1.启动"></a>2.5.1.启动</h3><blockquote>
<ul>
<li><code>SpringBoot</code> 启动的时候加载主配置类。在 <code>@SpringBootApplication</code> 开启了自动配置功能 <code>@EnableAutoConfiguration</code></li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SpringBootApplication</span>  <span class="comment">// 这里</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">SpringbootStudyApplication</span> </span>{</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>{</span><br><span class="line">        SpringApplication.run(SpringbootStudyApplication<span class="class">.<span class="keyword">class</span>, <span class="title">args</span>)</span>;</span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>

<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Target</span>({ElementType.TYPE})</span><br><span class="line"><span class="meta">@Retention</span>(RetentionPolicy.RUNTIME)</span><br><span class="line"><span class="meta">@Documented</span></span><br><span class="line"><span class="meta">@Inherited</span></span><br><span class="line"><span class="meta">@SpringBootConfiguration</span></span><br><span class="line"><span class="meta">@EnableAutoConfiguration</span>  <span class="comment">// 这里</span></span><br><span class="line"><span class="meta">@ComponentScan</span>(</span><br><span class="line">    excludeFilters = {<span class="meta">@Filter</span>(</span><br><span class="line">    type = FilterType.CUSTOM,</span><br><span class="line">    classes = {TypeExcludeFilter<span class="class">.<span class="keyword">class</span>}</span></span><br><span class="line"><span class="class">), @<span class="title">Filter</span>(</span></span><br><span class="line"><span class="class">    <span class="title">type</span> </span>= FilterType.CUSTOM,</span><br><span class="line">    classes = {AutoConfigurationExcludeFilter<span class="class">.<span class="keyword">class</span>}</span></span><br><span class="line"><span class="class">)}</span></span><br><span class="line"><span class="class">)</span></span><br><span class="line"><span class="class"><span class="title">public</span> @<span class="title">interface</span> <span class="title">SpringBootApplication</span> </span>{</span><br><span class="line">    </span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>
</blockquote>
<h3 id="2-5-2-EnableAutoConfiguration"><a href="#2-5-2-EnableAutoConfiguration" class="headerlink" title="2.5.2.@EnableAutoConfiguration"></a>2.5.2.@EnableAutoConfiguration</h3><blockquote>
<ul>
<li>而在 <code>@EnableAutoConfiguration</code> 中又通过 <code>@Import({AutoConfigurationImportSelector.class})</code> 自动导入了组件</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Target</span>({ElementType.TYPE})</span><br><span class="line"><span class="meta">@Retention</span>(RetentionPolicy.RUNTIME)</span><br><span class="line"><span class="meta">@Documented</span></span><br><span class="line"><span class="meta">@Inherited</span></span><br><span class="line"><span class="meta">@AutoConfigurationPackage</span></span><br><span class="line"><span class="meta">@Import</span>({AutoConfigurationImportSelector<span class="class">.<span class="keyword">class</span>})  // 这里</span></span><br><span class="line"><span class="class"><span class="title">public</span> @<span class="title">interface</span> <span class="title">EnableAutoConfiguration</span> </span>{</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>
</blockquote>
<h3 id="2-5-3-selectImports"><a href="#2-5-3-selectImports" class="headerlink" title="2.5.3.selectImports()"></a>2.5.3.selectImports()</h3><blockquote>
<ul>
<li>在 <code>AutoConfigurationImportSelector.class</code> 中，有一个 <code>selectImports()</code>  的方法，这个方法调用该类下面的 <code>getAutoConfigurationEntry()</code> 方法</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">AutoConfigurationImportSelector</span> <span class="keyword">implements</span> </span></span><br><span class="line"><span class="class">    <span class="title">DeferredImportSelector</span>, </span></span><br><span class="line"><span class="class">	<span class="title">BeanClassLoaderAware</span>, </span></span><br><span class="line"><span class="class">	<span class="title">ResourceLoaderAware</span>, </span></span><br><span class="line"><span class="class">	<span class="title">BeanFactoryAware</span>, </span></span><br><span class="line"><span class="class">	<span class="title">EnvironmentAware</span>, </span></span><br><span class="line"><span class="class">	<span class="title">Ordered</span> </span>{</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// selectImports</span></span><br><span class="line">    <span class="keyword">public</span> String[] selectImports(AnnotationMetadata annotationMetadata) {</span><br><span class="line">        <span class="keyword">if</span> (!<span class="keyword">this</span>.isEnabled(annotationMetadata)) {</span><br><span class="line">            <span class="keyword">return</span> NO_IMPORTS;</span><br><span class="line">        } <span class="keyword">else</span> {</span><br><span class="line">            AutoConfigurationMetadata autoConfigurationMetadata = AutoConfigurationMetadataLoader.loadMetadata(<span class="keyword">this</span>.beanClassLoader);</span><br><span class="line">            AutoConfigurationImportSelector.AutoConfigurationEntry autoConfigurationEntry = <span class="keyword">this</span>.getAutoConfigurationEntry(autoConfigurationMetadata, annotationMetadata);  <span class="comment">// 这里</span></span><br><span class="line">            <span class="keyword">return</span> StringUtils.toStringArray(autoConfigurationEntry.getConfigurations());</span><br><span class="line">        }</span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>
</blockquote>
<h3 id="2-5-4-getAutoConfigurationEntry"><a href="#2-5-4-getAutoConfigurationEntry" class="headerlink" title="2.5.4.getAutoConfigurationEntry()"></a>2.5.4.getAutoConfigurationEntry()</h3><blockquote>
<ul>
<li>在 <code>getAutoConfigurationEntry()</code> 方法中又调用该类中的 <code>getCandidateConfigurations()</code> 方法</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">AutoConfigurationImportSelector</span> <span class="keyword">implements</span> </span></span><br><span class="line"><span class="class">    <span class="title">DeferredImportSelector</span>, </span></span><br><span class="line"><span class="class">	<span class="title">BeanClassLoaderAware</span>, </span></span><br><span class="line"><span class="class">	<span class="title">ResourceLoaderAware</span>, </span></span><br><span class="line"><span class="class">	<span class="title">BeanFactoryAware</span>, </span></span><br><span class="line"><span class="class">	<span class="title">EnvironmentAware</span>, </span></span><br><span class="line"><span class="class">	<span class="title">Ordered</span> </span>{</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// getAutoConfigurationEntry</span></span><br><span class="line">    <span class="keyword">protected</span> AutoConfigurationImportSelector.<span class="function">AutoConfigurationEntry <span class="title">getAutoConfigurationEntry</span><span class="params">(AutoConfigurationMetadata autoConfigurationMetadata, AnnotationMetadata annotationMetadata)</span> </span>{</span><br><span class="line">        <span class="keyword">if</span> (!<span class="keyword">this</span>.isEnabled(annotationMetadata)) {</span><br><span class="line">            <span class="keyword">return</span> EMPTY_ENTRY;</span><br><span class="line">        } <span class="keyword">else</span> {</span><br><span class="line">            AnnotationAttributes attributes = <span class="keyword">this</span>.getAttributes(annotationMetadata);</span><br><span class="line">            List<string> configurations = <span class="keyword">this</span>.getCandidateConfigurations(annotationMetadata, attributes);  <span class="comment">// 这里</span></string></span><br><span class="line">            configurations = <span class="keyword">this</span>.removeDuplicates(configurations);</span><br><span class="line">            Set<string> exclusions = <span class="keyword">this</span>.getExclusions(annotationMetadata, attributes);</string></span><br><span class="line">            <span class="keyword">this</span>.checkExcludedClasses(configurations, exclusions);</span><br><span class="line">            configurations.removeAll(exclusions);</span><br><span class="line">            configurations = <span class="keyword">this</span>.filter(configurations, autoConfigurationMetadata);</span><br><span class="line">            <span class="keyword">this</span>.fireAutoConfigurationImportEvents(configurations, exclusions);</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> AutoConfigurationImportSelector.AutoConfigurationEntry(configurations, exclusions);</span><br><span class="line">        }</span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>
</blockquote>
<h3 id="2-5-5-loadFactoryNames"><a href="#2-5-5-loadFactoryNames" class="headerlink" title="2.5.5.loadFactoryNames()"></a>2.5.5.loadFactoryNames()</h3><blockquote>
<ul>
<li>在 <code>getCandidateConfigurations()</code> 中调用 <code>SpringFactoriesLoader.loadFactoryNames()</code> 方法</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">AutoConfigurationImportSelector</span> <span class="keyword">implements</span> </span></span><br><span class="line"><span class="class">    <span class="title">DeferredImportSelector</span>, </span></span><br><span class="line"><span class="class">	<span class="title">BeanClassLoaderAware</span>, </span></span><br><span class="line"><span class="class">	<span class="title">ResourceLoaderAware</span>, </span></span><br><span class="line"><span class="class">	<span class="title">BeanFactoryAware</span>, </span></span><br><span class="line"><span class="class">	<span class="title">EnvironmentAware</span>, </span></span><br><span class="line"><span class="class">	<span class="title">Ordered</span> </span>{</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// getCandidateConfigurations</span></span><br><span class="line">    <span class="function"><span class="keyword">protected</span> List<string> <span class="title">getCandidateConfigurations</span><span class="params">(AnnotationMetadata metadata, AnnotationAttributes attributes)</span> </string></span>{</span><br><span class="line">        List<string> configurations = SpringFactoriesLoader.loadFactoryNames(<span class="keyword">this</span>.getSpringFactoriesLoaderFactoryClass(), <span class="keyword">this</span>.getBeanClassLoader());  <span class="comment">// 这里</span></string></span><br><span class="line">        Assert.notEmpty(configurations, <span class="string">"No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct."</span>);</span><br><span class="line">        <span class="keyword">return</span> configurations;</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>
</blockquote>
<h3 id="2-5-6-loadFactoryNames"><a href="#2-5-6-loadFactoryNames" class="headerlink" title="2.5.6.loadFactoryNames()"></a>2.5.6.loadFactoryNames()</h3><blockquote>
<ul>
<li>在 <code>SpringFactoriesLoader.class</code> 的 <code>loadFactoryNames()</code> 中调用该类下面的 <code>loadSpringFactories()</code> 方法</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">final</span> <span class="class"><span class="keyword">class</span> <span class="title">SpringFactoriesLoader</span> </span>{</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// loadFactoryNames</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> List<string> <span class="title">loadFactoryNames</span><span class="params">(Class<!--?--> factoryType, @Nullable ClassLoader classLoader)</span> </string></span>{</span><br><span class="line">        String factoryTypeName = factoryType.getName();</span><br><span class="line">        <span class="keyword">return</span> (List)loadSpringFactories(classLoader).getOrDefault(factoryTypeName, Collections.emptyList()); <span class="comment">// 这里</span></span><br><span class="line">    }</span><br><span class="line">    </span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>
</blockquote>
<h3 id="2-5-7-loadSpringFactories"><a href="#2-5-7-loadSpringFactories" class="headerlink" title="2.5.7.loadSpringFactories"></a>2.5.7.loadSpringFactories</h3><blockquote>
<ul>
<li>在 <code>loadSpringFactories()</code> 方法里，通过扫描所有 <code>jar</code> 包下面的 <code>META-INF/spring.factories</code> 文件。在得到这个文件的 <code>url</code> 之后，对这个文件进行遍历，获取到 <code>EnableAutoConfiguration.class</code> 的值，并整合成一个 <code>properties</code> 文件。将结果放在 <code>LinkedMultiValueMap result</code> 里面进行返回</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">final</span> <span class="class"><span class="keyword">class</span> <span class="title">SpringFactoriesLoader</span> </span>{</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// loadSpringFactories</span></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> Map<string, list<string>> loadSpringFactories(<span class="meta">@Nullable</span> ClassLoader classLoader) {</string,></span><br><span class="line">        MultiValueMap<string, string> result = (MultiValueMap)cache.get(classLoader);</string,></span><br><span class="line">        <span class="keyword">if</span> (result != <span class="keyword">null</span>) {</span><br><span class="line">            <span class="keyword">return</span> result;</span><br><span class="line">        } <span class="keyword">else</span> {</span><br><span class="line">            <span class="keyword">try</span> {</span><br><span class="line">                Enumeration<url> urls = classLoader != <span class="keyword">null</span> ? classLoader.getResources(<span class="string">"META-INF/spring.factories"</span>) : ClassLoader.getSystemResources(<span class="string">"META-INF/spring.factories"</span>);</url></span><br><span class="line">                <span class="comment">// 结果集</span></span><br><span class="line">                LinkedMultiValueMap result = <span class="keyword">new</span> LinkedMultiValueMap();</span><br><span class="line"></span><br><span class="line">                <span class="keyword">while</span>(urls.hasMoreElements()) {</span><br><span class="line">                    <span class="comment">// url</span></span><br><span class="line">                    URL url = (URL)urls.nextElement();</span><br><span class="line">                    UrlResource resource = <span class="keyword">new</span> UrlResource(url);</span><br><span class="line">                    <span class="comment">// 封装成 properties</span></span><br><span class="line">                    Properties properties = PropertiesLoaderUtils.loadProperties(resource);</span><br><span class="line">                    Iterator var6 = properties.entrySet().iterator();</span><br><span class="line"></span><br><span class="line">                    <span class="keyword">while</span>(var6.hasNext()) {</span><br><span class="line">                        Entry<!--?, ?--> entry = (Entry)var6.next();</span><br><span class="line">                        String factoryTypeName = ((String)entry.getKey()).trim();</span><br><span class="line">                        String[] var9 = StringUtils.commaDelimitedListToStringArray((String)entry.getValue());</span><br><span class="line">                        <span class="keyword">int</span> var10 = var9.length;</span><br><span class="line"></span><br><span class="line">                        <span class="keyword">for</span>(<span class="keyword">int</span> var11 = <span class="number">0</span>; var11 < var10; ++var11) {</span><br><span class="line">                            String factoryImplementationName = var9[var11];</span><br><span class="line">                            result.add(factoryTypeName, factoryImplementationName.trim());</span><br><span class="line">                        }</span><br><span class="line">                    }</span><br><span class="line">                }</span><br><span class="line"></span><br><span class="line">                cache.put(classLoader, result);</span><br><span class="line">                <span class="keyword">return</span> result;</span><br><span class="line">            } <span class="keyword">catch</span> (IOException var13) {</span><br><span class="line">                <span class="keyword">throw</span> <span class="keyword">new</span> IllegalArgumentException(<span class="string">"Unable to load factories from location [META-INF/spring.factories]"</span>, var13);</span><br><span class="line">            }</span><br><span class="line">        }</span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>


</blockquote>
<h3 id="2-5-8-META-INF-spring-factories"><a href="#2-5-8-META-INF-spring-factories" class="headerlink" title="2.5.8.META-INF/spring.factories"></a>2.5.8.META-INF/spring.factories</h3><blockquote>
<ul>
<li>我们会在 <code>磁盘:\Maven 仓库路径\org\springframework\boot\spring-boot-autoconfigure\2.2.4.RELEASE\spring-boot-autoconfigure-2.2.4.RELEASE.jar!\META-INF\spring.factories</code> 中找到它遍历的内容，这就是自动配置之源</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">properties</div></div><figure class="highlight properties"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Auto Configure</span></span><br><span class="line"><span class="meta">org.springframework.boot.autoconfigure.EnableAutoConfiguration</span>=<span class="string">\</span></span><br><span class="line">org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.cloud.CloudServiceConnectorsAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveDataAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.cassandra.CassandraRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveDataAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.couchbase.CouchbaseRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveElasticsearchRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveRestClientAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.jdbc.JdbcRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.ldap.LdapRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.mongo.MongoReactiveRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.neo4j.Neo4jRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.solr.SolrRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.hazelcast.HazelcastJpaDependencyAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.influx.InfluxDbAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.jms.artemis.ArtemisAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.ldap.embedded.EmbeddedLdapAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.mail.MailSenderValidatorAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.rsocket.RSocketMessagingAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.rsocket.RSocketRequesterAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.rsocket.RSocketServerAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.rsocket.RSocketStrategiesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.security.servlet.SecurityFilterAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.security.rsocket.RSocketSecurityAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.sendgrid.SendGridAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.session.SessionAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.security.oauth2.client.reactive.ReactiveOAuth2ClientAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.security.oauth2.resource.reactive.ReactiveOAuth2ResourceServerAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFactoryAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.web.reactive.error.ErrorWebFluxAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.web.reactive.function.client.ClientHttpConnectorAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.web.reactive.function.client.WebClientAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.websocket.reactive.WebSocketReactiveAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.websocket.servlet.WebSocketMessagingAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.webservices.WebServicesAutoConfiguration,\</span><br><span class="line"><span class="attr">org.springframework.boot.autoconfigure.webservices.client.WebServiceTemplateAutoConfiguration</span></span><br></pre></td></tr></tbody></table></figure></div>
</blockquote>
<h3 id="2-5-9-加载组件"><a href="#2-5-9-加载组件" class="headerlink" title="2.5.9.加载组件"></a>2.5.9.加载组件</h3><blockquote>
<ul>
<li><p>以 <code>HttpEncodingAutoConfiguration</code> 为例，在这个类上有 5 个注解</p>
</li>
<li><p>这个自动配置类意思就是根据当前不同条件判断，决定这个判断是否生效</p>
</li>
<li><p>其中有一些属性需要从配置文件中获取值，而配置文件已经通过某个属性，形成了对应关系。比如这个 <code>HttpEncodingAutoConfiguration</code> 里面有一个 <code>properties</code>，这个属性是通过有参属性拿到的，而参数则是从 <code>@EnableConfigurationProperties({HttpProperties.class})</code> 注解中拿到</p>
</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HttpEncodingAutoConfiguration</span> </span>{</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">final</span> Encoding properties;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">HttpEncodingAutoConfiguration</span><span class="params">(HttpProperties properties)</span> </span>{</span><br><span class="line">        <span class="keyword">this</span>.properties = properties.getEncoding();</span><br><span class="line">    }</span><br><span class="line">    </span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>
</blockquote>
<h4 id="Configuration-proxyBeanMethods-false"><a href="#Configuration-proxyBeanMethods-false" class="headerlink" title="- @Configuration(proxyBeanMethods = false)"></a>- @Configuration(proxyBeanMethods = false)</h4><blockquote>
<ul>
<li>用于表示这是一个配置类</li>
</ul>
</blockquote>
<h4 id="EnableConfigurationProperties-HttpProperties-class"><a href="#EnableConfigurationProperties-HttpProperties-class" class="headerlink" title="- @EnableConfigurationProperties({HttpProperties.class})"></a>- @EnableConfigurationProperties({HttpProperties.class})</h4><blockquote>
<ul>
<li>启用 <code>ConfigurationProperties</code> 功能，打开 <code>HttpProperties.class</code> 会发现这个类标注了 <code>@ConfigurationProperties</code> 注解，这个注解就是从配置文件获取指定的值和 <code>bean</code> 的属性进行绑定，并把 <code>HttpProperties</code> 加入到容器中</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@ConfigurationProperties</span>(prefix = <span class="string">"spring.http"</span>)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HttpProperties</span> </span>{</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>

<ul>
<li>到此，我们就可以参考该类里面的属性，对配置做出精确修改，比如在这个类中有 <code>Encoding</code> 这个内部类，就可以通过 <code>spring.http.encoding.charset</code> 来配置字符编码，前面的 <code>spring.http</code> 来自于注解上的前缀 <code>prefix = "spring.http"</code></li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@ConfigurationProperties</span>(prefix = <span class="string">"spring.http"</span>)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HttpProperties</span> </span>{</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">Encoding</span> </span>{</span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> Charset DEFAULT_CHARSET;</span><br><span class="line">        <span class="keyword">private</span> Charset charset;</span><br><span class="line">        <span class="keyword">private</span> Boolean force;</span><br><span class="line">        <span class="keyword">private</span> Boolean forceRequest;</span><br><span class="line">        <span class="keyword">private</span> Boolean forceResponse;</span><br><span class="line">        <span class="keyword">private</span> Map<locale, charset> mapping;</locale,></span><br><span class="line">    }</span><br><span class="line">    </span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>
</blockquote>
<h4 id="ConditionalOnWebApplication-type-Type-SERVLET"><a href="#ConditionalOnWebApplication-type-Type-SERVLET" class="headerlink" title="- @ConditionalOnWebApplication(type = Type.SERVLET)"></a>- @ConditionalOnWebApplication(type = Type.SERVLET)</h4><blockquote>
<ul>
<li>根据条件不同，如果满足指定的条件，整个配置类里面的配置就会生效</li>
</ul>
</blockquote>
<h4 id="ConditionalOnClass-CharacterEncodingFilter-class"><a href="#ConditionalOnClass-CharacterEncodingFilter-class" class="headerlink" title="- @ConditionalOnClass({CharacterEncodingFilter.class})"></a>- @ConditionalOnClass({CharacterEncodingFilter.class})</h4><blockquote>
<ul>
<li>判断当前项目有没有这个类</li>
</ul>
</blockquote>
<h4 id="ConditionalOnProperty-prefix-“spring-http-encoding”-value-“enabled”-matchIfMissing-true"><a href="#ConditionalOnProperty-prefix-“spring-http-encoding”-value-“enabled”-matchIfMissing-true" class="headerlink" title="- @ConditionalOnProperty(prefix = “spring.http.encoding”, value = {“enabled”}, matchIfMissing = true)"></a>- @ConditionalOnProperty(prefix = “spring.http.encoding”, value = {“enabled”}, matchIfMissing = true)</h4><blockquote>
<ul>
<li>判断配置文件中是否存在某个配置，这里判断的是 <code>spring.http.encoding.enable</code>，而 <code>matchIfMissing = true</code> 意思就是说，如果没有则默认生效</li>
</ul>
</blockquote>
<h2 id="2-6-Conditional"><a href="#2-6-Conditional" class="headerlink" title="2.6.Conditional"></a>2.6.Conditional</h2><table>
<thead>
<tr>
<th>注解</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td><code>@ConditionalOnJava</code></td>
<td>系统的 <code>Java</code> 是否符合要求</td>
</tr>
<tr>
<td><code>@ConditionalOnBean</code></td>
<td>容器中存在指定的 <code>Bean</code></td>
</tr>
<tr>
<td><code>@ConditionalOnMissingBean</code></td>
<td>容器中没有指定的 <code>Bean</code></td>
</tr>
<tr>
<td><code>@ConditionalOnExpression</code></td>
<td>满足 <code>SpEL</code> 表达式</td>
</tr>
<tr>
<td><code>@ConditionalOnClass</code></td>
<td>系统中有指定的类</td>
</tr>
<tr>
<td><code>@ConditionalOnMissingClass</code></td>
<td>系统中没有指定的类</td>
</tr>
<tr>
<td><code>@ConditionalOnSingleCandidate</code></td>
<td>容器中只有一个指定的 <code>Bean</code>，或者这个是首选 <code>Bean</code></td>
</tr>
<tr>
<td><code>@ConditionalOnProperty</code></td>
<td>系统中的属性是否有指定的值</td>
</tr>
<tr>
<td><code>@ConditionalOnResource</code></td>
<td>类路径下是否存在指定的资源文件</td>
</tr>
<tr>
<td><code>@ConditionalOnWebApplication</code></td>
<td>当前是 <code>web</code> 环境</td>
</tr>
<tr>
<td><code>@ConditionalOnNotWebApplication</code></td>
<td>当前不是 <code>web</code> 环境</td>
</tr>
<tr>
<td><code>@ConditionalOnJndi</code></td>
<td><code>JNDI</code> 存在指定项</td>
</tr>
</tbody></table>
<h2 id="2-7-自动配置报告"><a href="#2-7-自动配置报告" class="headerlink" title="2.7.自动配置报告"></a>2.7.自动配置报告</h2><blockquote>
<p>因为自动配置类都是需要满足一定条件才能生效，所以一开始并不会加载所有自动配置类。我们需要知道哪些自动配置类起作用，才能精确做出相应配置</p>
<p>我们可以在核心配置文件中进行配置：<code>debug = true</code> ，当项目启动时，在控制台就会有自动配置报告，显示出哪些自动配置类启用了，哪些自动配置没启动</p>
</blockquote>
<h1 id="三、日志"><a href="#三、日志" class="headerlink" title="三、日志"></a>三、日志</h1><h2 id="3-1-SLF4j的使用原理"><a href="#3-1-SLF4j的使用原理" class="headerlink" title="3.1.SLF4j的使用原理"></a>3.1.SLF4j的使用原理</h2><p><a target="_blank" rel="noopener" href="http://slf4j.org/images/concrete-bindings.png" data-fancybox="group" data-caption="SLF4J" class="fancybox"><img alt="SLF4J" title="SLF4J" data-src="http://slf4j.org/images/concrete-bindings.png" class="lazyload"></a></p>
<h2 id="3-2-统一日志框架"><a href="#3-2-统一日志框架" class="headerlink" title="3.2.统一日志框架"></a>3.2.统一日志框架</h2><p><a target="_blank" rel="noopener" href="http://www.slf4j.org/images/legacy.png" data-fancybox="group" data-caption class="fancybox"><img alt title data-src="http://www.slf4j.org/images/legacy.png" class="lazyload"></a></p>
<blockquote>
<ul>
<li>将系统中的其他日志框架排除</li>
<li>用中间包来替换原有的日志框架</li>
<li>导入 <code>slf4j</code> 的其他实现</li>
</ul>
</blockquote>
<h2 id="3-3-SpringBoot-日志关系"><a href="#3-3-SpringBoot-日志关系" class="headerlink" title="3.3.SpringBoot 日志关系"></a>3.3.SpringBoot 日志关系</h2><p><a href="F:%5CSoftFilesOneDriveTyporaimg%5Cimage-20200221205710185.png" data-fancybox="group" data-caption="image-20200221205710185" class="fancybox"><img alt="image-20200221205710185" title="image-20200221205710185" data-src="F:%5CSoftFilesOneDriveTyporaimg%5Cimage-20200221205710185.png" class="lazyload"></a></p>
<h2 id="3-4-使用日志"><a href="#3-4-使用日志" class="headerlink" title="3.4.使用日志"></a>3.4.使用日志</h2><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">Logger log = LoggerFactory.getLogger(getClass());</span><br><span class="line"></span><br><span class="line">log.trace(); <span class="comment">// 跟踪信息</span></span><br><span class="line">log.debug();</span><br><span class="line">log.info();</span><br><span class="line">log.warn();</span><br><span class="line">log.error();</span><br><span class="line"></span><br><span class="line"><span class="comment">// 级别由低到高</span></span><br><span class="line"><span class="comment">// 默认级别是 info，即只输出 info 以后的信息</span></span><br></pre></td></tr></tbody></table></figure></div>

<p><strong>logging.level.包路径 = 级别</strong></p>
<blockquote>
<p>调整日志的级别</p>
</blockquote>
<p><strong>logging.file=磁盘：/路径/?.log</strong></p>
<blockquote>
<p>在指定位置生成日志文件</p>
</blockquote>
<p><strong>logging.path=路径</strong></p>
<blockquote>
<p>在当前磁盘的根目录，根据指定路径创建名为 <code>spring.log</code> 的日志文件</p>
</blockquote>
<p><strong>logging.parttern.console=?</strong></p>
<blockquote>
<p>设置在控制台的打印信息</p>
<p>日志输出格式</p>
<ul>
<li><strong>%d</strong> 日期</li>
<li><strong>%thread</strong> 线程名</li>
<li><strong>%-5level</strong> 左对齐</li>
<li><strong>%logger{50}</strong> logger 名最长 50 个字符否则按照句点分割</li>
<li><strong>%msg</strong> 日志消息</li>
<li><strong>%n</strong> 换行符</li>
</ul>
</blockquote>
<p><strong>logging.parttern.file=?</strong></p>
<blockquote>
<p>设置在文件中的打印信息</p>
</blockquote>
<h3 id="3-5-高级特性"><a href="#3-5-高级特性" class="headerlink" title="3.5.高级特性"></a>3.5.高级特性</h3><blockquote>
<p>如需自己去配置日志文件，可参照下表，在 <code>classpath</code> 中建立相应文件进行配置</p>
</blockquote>
<table>
<thead>
<tr>
<th>日志系统</th>
<th>自定义配置文件</th>
</tr>
</thead>
<tbody><tr>
<td>Logback</td>
<td><code>logback-spring.xml</code>, <code>logback-spring.groovy</code>, <code>logback.xml</code> or <code>logback.groovy</code></td>
</tr>
<tr>
<td>Log4j2</td>
<td><code>log4j2-spring.xml</code> or <code>log4j2.xml</code></td>
</tr>
<tr>
<td>JDK (Java Util Logging)</td>
<td><code>logging.properties</code></td>
</tr>
</tbody></table>
<blockquote>
<p><code>SpringBoot</code> 官方建议当我们使用 <code>logback</code> 日志系统时在配置文件名后面加一个 <code>-spring</code> 的后缀，因为在加载的过程中，日志系统能直接识别 <code>logback.xml</code> ，这样虽然没问题，但是直接绕过了 <code>SpringBoot</code> ，当我们加上 <code>-spring</code> 后缀之后，日志系统就不能直接识别这个配置文件，该文件就会由 <code>SpringBoot</code> 进行处理，在这种情况下，我们就能使用 <code>SpringBoot</code> 日志系统的一个高级特性 —— 在不同的 <code>profile</code> 环境设置不同的输出配置</p>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">springProfile</span> <span class="attr">name</span>=<span class="string">"?"</span>></span></span><br><span class="line"></span><br><span class="line"><span class="tag">< /<span class="attr">springProfile</span>></span></span><br><span class="line"></span><br><span class="line">// ?: dev/prod/root</span><br></pre></td></tr></tbody></table></figure></div>
</blockquote>
<h1 id="四、Web-开发"><a href="#四、Web-开发" class="headerlink" title="四、Web 开发"></a>四、Web 开发</h1><h2 id="4-1-静态资源映射规则"><a href="#4-1-静态资源映射规则" class="headerlink" title="4.1.静态资源映射规则"></a>4.1.静态资源映射规则</h2><p><strong>静态资源</strong></p>
<blockquote>
<p>有关 <code>Web</code> 开发的相关配置都在 <code>WebMvcAutoConfiguration.class</code> 中，其中的 <code>addResourceHandlers()</code> 方法指定了访问的路径</p>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">addResourceHandlers</span><span class="params">(ResourceHandlerRegistry registry)</span> </span>{</span><br><span class="line"> <span class="keyword">if</span> (!<span class="keyword">this</span>.resourceProperties.isAddMappings()) {</span><br><span class="line">     logger.debug(<span class="string">"Default resource handling disable	d"</span>);</span><br><span class="line"> } <span class="keyword">else</span> {</span><br><span class="line">     Duration cachePeriod = <span class="keyword">this</span>.resourceProperties.getCache().getPeriod();</span><br><span class="line">     CacheControl cacheControl = <span class="keyword">this</span>.resourceProperties.getCache().getCachecontrol().toHttpCacheControl();</span><br><span class="line">     <span class="keyword">if</span> (!registry.hasMappingForPattern(<span class="string">"/webjars/**"</span>)) {</span><br><span class="line">         <span class="keyword">this</span>.customizeResourceHandlerRegistration(registry.addResourceHandler(<span class="keyword">new</span> String[]{<span class="string">"/webjars/**"</span>}).addResourceLocations(<span class="keyword">new</span> String[]{<span class="string">"classpath:/META-INF/resources/webjars/"</span>}).setCachePeriod(<span class="keyword">this</span>.getSeconds(cachePeriod)).setCacheControl(cacheControl));</span><br><span class="line">     }</span><br><span class="line"></span><br><span class="line">     String staticPathPattern = <span class="keyword">this</span>.mvcProperties.getStaticPathPattern();</span><br><span class="line">     <span class="keyword">if</span> (!registry.hasMappingForPattern(staticPathPattern)) {</span><br><span class="line">         <span class="keyword">this</span>.customizeResourceHandlerRegistration(registry.addResourceHandler(<span class="keyword">new</span> String[]{staticPathPattern}).addResourceLocations(WebMvcAutoConfiguration.getResourceLocations(<span class="keyword">this</span>.resourceProperties.getStaticLocations())).setCachePeriod(<span class="keyword">this</span>.getSeconds(cachePeriod)).setCacheControl(cacheControl));</span><br><span class="line">     }</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>

<ul>
<li>该方法限定了所有 <code>/webjars/**</code> 的访问，都去 <code>/META-INF/resources/webjars/</code> 里面找</li>
<li><code>webjars</code> 以 <code>jar</code> 包的形式导入静态资源</li>
<li>该方法还限定了自己的静态资源在哪里找，<code>this.mvcProperties.getStaticPathPattern()</code> 通过这个方法获取到 <code>/**</code> 即：不是 <code>/webjars/**</code> 时的处理方法，又通过 <code>this.resourceProperties.getStaticLocations()</code> 获取到了这个访问方法的访问路径、</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">"classpath:/META-INF/resources/"</span></span><br><span class="line"><span class="string">"classpath:/resources/"</span></span><br><span class="line"><span class="string">"classpath:/static/"</span></span><br><span class="line"><span class="string">"classpath:/public/"</span></span><br></pre></td></tr></tbody></table></figure></div>
</blockquote>
<p><strong>欢迎页</strong></p>
<blockquote>
<p>在 <code>WebMvcAutoConfiguration.class</code> 中有 <code>WelcomePageHandlerMapping()</code> 方法</p>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> WelcomePageHandlerMapping <span class="title">welcomePageHandlerMapping</span><span class="params">(</span></span></span><br><span class="line"><span class="function"><span class="params"> ApplicationContext applicationContext, </span></span></span><br><span class="line"><span class="function"><span class="params"> FormattingConversionService mvcConversionService, </span></span></span><br><span class="line"><span class="function"><span class="params"> ResourceUrlProvider mvcResourceUrlProvider)</span> </span>{</span><br><span class="line"> WelcomePageHandlerMapping welcomePageHandlerMapping = <span class="keyword">new</span> WelcomePageHandlerMapping(<span class="keyword">new</span> TemplateAvailabilityProviders(applicationContext), applicationContext, <span class="keyword">this</span>.getWelcomePage(), <span class="keyword">this</span>.mvcProperties.getStaticPathPattern());</span><br><span class="line"> welcomePageHandlerMapping.setInterceptors(<span class="keyword">this</span>.getInterceptors(mvcConversionService, mvcResourceUrlProvider));</span><br><span class="line"> <span class="keyword">return</span> welcomePageHandlerMapping;</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>

<p>在这个方法里又调用 <code>getWelcomePage()</code> 方法和 <code>getStaticPathPattern()</code> 方法，分别获取欢迎页和它的映射路径</p>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">private</span> Optional<resource> <span class="title">getWelcomePage</span><span class="params">()</span> </resource></span>{</span><br><span class="line"> String[] locations = WebMvcAutoConfiguration.getResourceLocations(<span class="keyword">this</span>.resourceProperties.getStaticLocations());</span><br><span class="line"> <span class="keyword">return</span> Arrays.stream(locations).map(<span class="keyword">this</span>::getIndexHtml).filter(<span class="keyword">this</span>::isReadable).findFirst();</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">private</span> Resource <span class="title">getIndexHtml</span><span class="params">(String location)</span> </span>{</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">this</span>.resourceLoader.getResource(location + <span class="string">"index.html"</span>);</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>

<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> String <span class="title">getStaticPathPattern</span><span class="params">()</span> </span>{</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">this</span>.staticPathPattern;</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>

<p>我们可以发现，欢迎页就是 <code>staticPathPattern</code> 下的 <code>***.index</code> 文件</p>
</blockquote>
</body></html></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a href="mailto:undefined">Cying-承影</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="http://cyingk.github.io/2020/04/05/SpringBoot/">http://cyingk.github.io/2020/04/05/SpringBoot/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/JavaEE/">JavaEE</a></div><div class="post_share"></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2020/04/08/Operating-System/"><img class="prev-cover" src="http://narpro.top/img/os.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">Previous Post</div><div class="prev_info">Operating_System</div></div></a></div><div class="next-post pull-right"><a href="/2020/03/29/Manjaro/"><img class="next-cover" src="https://img-blog.csdnimg.cn/20200329210424371.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">Next Post</div><div class="next_info">Manjaro</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> Related Articles</span></div><div class="relatedPosts-list"><div><a href="/2020/08/06/Linux-And-Docker/" title="SpringCloud With Docker"><img class="cover" src="https://img-blog.csdnimg.cn/202008061653587.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-08-06</div><div class="title">SpringCloud With Docker</div></div></a></div><div><a href="/2020/05/05/SpringCloud/" title="SpringCloud"><img class="cover" src="http://img3.imgtn.bdimg.com/it/u=1799420697,1254911040&fm=26&gp=0.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-05-05</div><div class="title">SpringCloud</div></div></a></div><div><a href="/2020/02/20/Mybatis/" title="MyBatis"><img class="cover" src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=575314515,4268715674&fm=26&gp=0.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-02-20</div><div class="title">MyBatis</div></div></a></div><div><a href="/2020/02/16/SpringMVC/" title="SpringMVC"><img class="cover" src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=790255512,3591398303&fm=26&gp=0.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-02-16</div><div class="title">SpringMVC</div></div></a></div><div><a href="/2020/02/15/Hibernate/" title="Hibernate"><img class="cover" src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=607365457,3589909035&fm=26&gp=0.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-02-15</div><div class="title">Hibernate</div></div></a></div><div><a href="/2020/02/01/Struts2/" title="Struts2"><img class="cover" src="https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2597327423,2034793762&fm=26&gp=0.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-02-01</div><div class="title">Struts2</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Catalog</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">1.</span> <span class="toc-text">SpringBoot</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%80%E3%80%81SpringBoot-%E5%85%A5%E9%97%A8"><span class="toc-number">2.</span> <span class="toc-text">一、SpringBoot 入门</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-1-%E7%AE%80%E4%BB%8B"><span class="toc-number">2.1.</span> <span class="toc-text">1.1 - 简介</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-1-1-%E8%83%8C%E6%99%AF"><span class="toc-number">2.1.1.</span> <span class="toc-text">1.1.1.背景</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-1-2-%E8%A7%A3%E5%86%B3"><span class="toc-number">2.1.2.</span> <span class="toc-text">1.1.2.解决</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-1-3-%E4%BC%98%E7%82%B9"><span class="toc-number">2.1.3.</span> <span class="toc-text">1.1.3.优点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-1-4-%E5%BE%AE%E6%9C%8D%E5%8A%A1"><span class="toc-number">2.1.4.</span> <span class="toc-text">1.1.4.微服务</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-2-pom-xml"><span class="toc-number">2.2.</span> <span class="toc-text">1.2 - pom.xml</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-2-1-%E4%BE%9D%E8%B5%96"><span class="toc-number">2.2.1.</span> <span class="toc-text">1.2.1.依赖</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#lt-parent-gt-%E2%80%A6-lt-parent-gt"><span class="toc-number">2.2.1.1.</span> <span class="toc-text">- …&lt; &#x2F;parent&gt;</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#lt-build-gt-%E2%80%A6-lt-bulid-gt"><span class="toc-number">2.2.1.2.</span> <span class="toc-text">- …&lt; &#x2F;bulid&gt;</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#lt-dependencies-gt-%E2%80%A6-lt-dependencies-gt"><span class="toc-number">2.2.1.3.</span> <span class="toc-text">- …&lt; &#x2F;dependencies&gt;</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-2-2-%E5%88%86%E6%9E%90"><span class="toc-number">2.2.2.</span> <span class="toc-text">1.2.2.分析</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-3-%E6%B3%A8%E8%A7%A3"><span class="toc-number">2.3.</span> <span class="toc-text">1.3. - 注解</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#SpringBootApplication"><span class="toc-number">2.3.1.</span> <span class="toc-text">- @SpringBootApplication</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Controller"><span class="toc-number">2.3.2.</span> <span class="toc-text">- @Controller</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#RequestMapping-%E2%80%9Curl%E2%80%9D"><span class="toc-number">2.3.3.</span> <span class="toc-text">- @RequestMapping(“url”)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ResponseBody"><span class="toc-number">2.3.4.</span> <span class="toc-text">- @ResponseBody</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#RestController"><span class="toc-number">2.3.5.</span> <span class="toc-text">- @RestController</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ConfigurationProperties-prefix-%E2%80%9C%E5%AF%B9%E8%B1%A1%E2%80%9D"><span class="toc-number">2.3.6.</span> <span class="toc-text">- @ConfigurationProperties(prefix &#x3D; “对象”)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Value-%E2%80%9C-%E2%80%9D"><span class="toc-number">2.3.7.</span> <span class="toc-text">- @Value(“${?}”)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#PropertySource-%E2%80%9Cclasspath-%E2%80%9D"><span class="toc-number">2.3.8.</span> <span class="toc-text">- @PropertySource(“classpath:?”)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ImportResource-locations-%E2%80%9Cclasspath-xml%E2%80%9D"><span class="toc-number">2.3.9.</span> <span class="toc-text">- @ImportResource(locations &#x3D; {“classpath:?.xml”})</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Configuration"><span class="toc-number">2.3.10.</span> <span class="toc-text">- @Configuration</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Bean"><span class="toc-number">2.3.11.</span> <span class="toc-text">- @Bean</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%8C%E3%80%81SpringBoot-%E9%85%8D%E7%BD%AE"><span class="toc-number">3.</span> <span class="toc-text">二、SpringBoot 配置</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#2-1-YAML"><span class="toc-number">3.1.</span> <span class="toc-text">2.1 - YAML</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-1-%E8%AF%AD%E6%B3%95"><span class="toc-number">3.1.1.</span> <span class="toc-text">2.1.1.语法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-2-%E5%AD%97%E9%9D%A2%E9%87%8F%E7%9A%84%E8%A1%A8%E7%A4%BA"><span class="toc-number">3.1.2.</span> <span class="toc-text">2.1.2.字面量的表示</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-3-%E5%AF%B9%E8%B1%A1%E7%9A%84%E8%A1%A8%E7%A4%BA"><span class="toc-number">3.1.3.</span> <span class="toc-text">2.1.3.对象的表示</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-4-%E6%95%B0%E7%BB%84%E7%9A%84%E8%A1%A8%E7%A4%BA"><span class="toc-number">3.1.4.</span> <span class="toc-text">2.1.4.数组的表示</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-2-Properties"><span class="toc-number">3.2.</span> <span class="toc-text">2.2 - Properties</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-3-Profile"><span class="toc-number">3.3.</span> <span class="toc-text">2.3 - Profile</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-3-1-Properties-%E9%85%8D%E7%BD%AE%E6%96%B9%E5%BC%8F"><span class="toc-number">3.3.1.</span> <span class="toc-text">2.3.1.Properties 配置方式</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-3-2-Yaml-%E9%85%8D%E7%BD%AE%E6%96%B9%E5%BC%8F"><span class="toc-number">3.3.2.</span> <span class="toc-text">2.3.2.Yaml 配置方式</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-3-3-%E5%85%B6%E4%BB%96%E6%96%B9%E5%BC%8F"><span class="toc-number">3.3.3.</span> <span class="toc-text">2.3.3.其他方式</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-4-%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E7%9A%84%E5%8A%A0%E8%BD%BD"><span class="toc-number">3.4.</span> <span class="toc-text">2.4.配置文件的加载</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-4-1-SpringBoot-%E6%8C%87%E5%AE%9A%E7%9A%84%E4%BD%8D%E7%BD%AE"><span class="toc-number">3.4.1.</span> <span class="toc-text">2.4.1.SpringBoot 指定的位置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-4-2-%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9A%84%E4%BD%8D%E7%BD%AE"><span class="toc-number">3.4.2.</span> <span class="toc-text">2.4.2.自定义的位置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-4-3-%E5%85%B6%E4%BB%96%E5%A4%96%E9%83%A8%E9%85%8D%E7%BD%AE%E4%BD%8D%E7%BD%AE"><span class="toc-number">3.4.3.</span> <span class="toc-text">2.4.3.其他外部配置位置</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-5-%E8%87%AA%E5%8A%A8%E9%85%8D%E7%BD%AE%E5%8E%9F%E7%90%86"><span class="toc-number">3.5.</span> <span class="toc-text">2.5.自动配置原理</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-5-1-%E5%90%AF%E5%8A%A8"><span class="toc-number">3.5.1.</span> <span class="toc-text">2.5.1.启动</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-5-2-EnableAutoConfiguration"><span class="toc-number">3.5.2.</span> <span class="toc-text">2.5.2.@EnableAutoConfiguration</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-5-3-selectImports"><span class="toc-number">3.5.3.</span> <span class="toc-text">2.5.3.selectImports()</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-5-4-getAutoConfigurationEntry"><span class="toc-number">3.5.4.</span> <span class="toc-text">2.5.4.getAutoConfigurationEntry()</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-5-5-loadFactoryNames"><span class="toc-number">3.5.5.</span> <span class="toc-text">2.5.5.loadFactoryNames()</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-5-6-loadFactoryNames"><span class="toc-number">3.5.6.</span> <span class="toc-text">2.5.6.loadFactoryNames()</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-5-7-loadSpringFactories"><span class="toc-number">3.5.7.</span> <span class="toc-text">2.5.7.loadSpringFactories</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-5-8-META-INF-spring-factories"><span class="toc-number">3.5.8.</span> <span class="toc-text">2.5.8.META-INF&#x2F;spring.factories</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-5-9-%E5%8A%A0%E8%BD%BD%E7%BB%84%E4%BB%B6"><span class="toc-number">3.5.9.</span> <span class="toc-text">2.5.9.加载组件</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#Configuration-proxyBeanMethods-false"><span class="toc-number">3.5.9.1.</span> <span class="toc-text">- @Configuration(proxyBeanMethods &#x3D; false)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#EnableConfigurationProperties-HttpProperties-class"><span class="toc-number">3.5.9.2.</span> <span class="toc-text">- @EnableConfigurationProperties({HttpProperties.class})</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ConditionalOnWebApplication-type-Type-SERVLET"><span class="toc-number">3.5.9.3.</span> <span class="toc-text">- @ConditionalOnWebApplication(type &#x3D; Type.SERVLET)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ConditionalOnClass-CharacterEncodingFilter-class"><span class="toc-number">3.5.9.4.</span> <span class="toc-text">- @ConditionalOnClass({CharacterEncodingFilter.class})</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ConditionalOnProperty-prefix-%E2%80%9Cspring-http-encoding%E2%80%9D-value-%E2%80%9Cenabled%E2%80%9D-matchIfMissing-true"><span class="toc-number">3.5.9.5.</span> <span class="toc-text">- @ConditionalOnProperty(prefix &#x3D; “spring.http.encoding”, value &#x3D; {“enabled”}, matchIfMissing &#x3D; true)</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-6-Conditional"><span class="toc-number">3.6.</span> <span class="toc-text">2.6.Conditional</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-7-%E8%87%AA%E5%8A%A8%E9%85%8D%E7%BD%AE%E6%8A%A5%E5%91%8A"><span class="toc-number">3.7.</span> <span class="toc-text">2.7.自动配置报告</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%89%E3%80%81%E6%97%A5%E5%BF%97"><span class="toc-number">4.</span> <span class="toc-text">三、日志</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#3-1-SLF4j%E7%9A%84%E4%BD%BF%E7%94%A8%E5%8E%9F%E7%90%86"><span class="toc-number">4.1.</span> <span class="toc-text">3.1.SLF4j的使用原理</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-2-%E7%BB%9F%E4%B8%80%E6%97%A5%E5%BF%97%E6%A1%86%E6%9E%B6"><span class="toc-number">4.2.</span> <span class="toc-text">3.2.统一日志框架</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-3-SpringBoot-%E6%97%A5%E5%BF%97%E5%85%B3%E7%B3%BB"><span class="toc-number">4.3.</span> <span class="toc-text">3.3.SpringBoot 日志关系</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-4-%E4%BD%BF%E7%94%A8%E6%97%A5%E5%BF%97"><span class="toc-number">4.4.</span> <span class="toc-text">3.4.使用日志</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-5-%E9%AB%98%E7%BA%A7%E7%89%B9%E6%80%A7"><span class="toc-number">4.4.1.</span> <span class="toc-text">3.5.高级特性</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9B%9B%E3%80%81Web-%E5%BC%80%E5%8F%91"><span class="toc-number">5.</span> <span class="toc-text">四、Web 开发</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#4-1-%E9%9D%99%E6%80%81%E8%B5%84%E6%BA%90%E6%98%A0%E5%B0%84%E8%A7%84%E5%88%99"><span class="toc-number">5.1.</span> <span class="toc-text">4.1.静态资源映射规则</span></a></li></ol></li></ol></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="footer_custom_text">却道天凉好个秋</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="Increase font size"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="Decrease font size"><i class="fas fa-minus"></i></button><button id="darkmode" type="button" title="Switch Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>if (document.getElementsByClassName('mermaid').length) {
  if (window.mermaidJsLoad) mermaid.init()
  else {
    getScript('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js').then(() => {
      window.mermaidJsLoad = true
      mermaid.initialize({
        theme: 'default',
      })
      false && mermaid.init()
    })
  }
}</script></div><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>